//用户登录
const db=require("../lib/db")

function userLogin(username,userpwd){
    return new Promise((resolve,reject)=>{
        let sql ="select * from user where userName='"+username+"'";
        db.querySql(sql).then(data=>{
            if(data.length==0){
                //用户不存在
                resolve(501)
            }else{
                if(data[0].userPassword==userpwd){
                    //登陆成功
                    resolve(data[0])
                }else{
                    //密码错误
                    resolve(502)
                }
            }
        })

    }) 
}

//导出
module.exports=userLogin